package com.example.pages;


import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.util.List;

public class MovieListPage extends InternalPage {
	
	@FindBy (className = "content")
	public WebElement contentMovie;
	
	@FindBy (css = "img[alt=\"Add movie\"]")
	public WebElement buttonAddMovie;
	
	@FindBy (className = "movie_box")
	public WebElement movie;
	
	@FindBy(css = "div.movie_cover")
	public List<WebElement> ListOfMovies;

	public int quantityOfMovies() {
		return ListOfMovies.size();
				//getText().equals("No movies where found.");
	}
	
	public boolean OpenMovieByName(String name) {
		System.out.println ("Looking for"+name);
		for (WebElement movieInList : ListOfMovies) {
			//if (movieInList.findElements(By.cssSelector("div[title=name]")).size() >0){
			
			if (name.equals(movieInList.findElement(By.cssSelector("div")).getAttribute("title"))){
				System.out.println ("Get it!!");
				movieInList.click();
				return true;
			}
			else{
				System.out.println ("Checking this film now");
				System.out.println(movieInList.findElement(By.cssSelector("div")).getAttribute("title"));
			}
		}
		return false;
				//getText().equals("No movies where found.");
	}
 }

